package com.itheima.stock.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.itheima.stock.common.domain.*;
import com.itheima.stock.pojo.StockBusiness;
import com.itheima.stock.pojo.StockRtInfo;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.req.PageResult;
import com.itheima.stock.vo.resp.R;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 定义股票信息控制器
 */
@RestController
@RequestMapping("/api/quot")
@CrossOrigin
public class StockController {
    @Autowired
    private StockService stockService;

    @GetMapping("stock/business/all")
        public List<StockBusiness> findStockBusiness(){
        return stockService.findAll();
    }

    //获取最新大盘参数
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarketInfos(){
        return stockService.getInnerMarketInfos();
    }
    //获取板块前十条记录：
    @GetMapping("sector/all")
    public R<List<StockBlockDomain>> getStockBlockInfos(){
        return stockService.getStockBlockInfos();
    }

    //do:涨幅榜前十
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getStockUpDownInfos(){
        return stockService.getStockUpDownInfos();
    }

    //分页查询
    @GetMapping("stock/all")
    public R<PageResult<StockUpdownDomain>> getStockByPage(@RequestParam(required = false,defaultValue = "1") Integer page,

                                                           @RequestParam(required = false,defaultValue = "20")  Integer pageSize){
        return stockService.getStockByPage(page,pageSize);

    }
    //涨停数量折线图显示
    @GetMapping("stock/updown/count")
    public R<Map> getStockUpdownCount(){
        return stockService.getStockUpdownCount();
    }

    //导出个股数据
    @GetMapping("stock/export")
    public void exportStockInfoExcel(HttpServletResponse resp,@RequestParam(required = false,defaultValue = "1") Integer page,

                                     @RequestParam(required = false,defaultValue = "20")  Integer pageSize){

        stockService.exportStockInfoExcel(resp,page,pageSize);
    }

    //成交量对比
    @GetMapping("stock/tradevol")
    public R<Map<String,List>> getStockTradeVol(){
        return stockService.getTradeVolT_1();
    }

    //个股涨幅区间统计
    @GetMapping("stock/updown")
    public R<Map> getStockUpdownScopeNum(){
        return stockService.getStockUpdownScopeNum();
    }

    //个股分时图：
    @GetMapping("stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStockMinuteInfo(String code){
        return stockService.getStockMinuteInfo(code);
    }
    //个股k线图
    @GetMapping("stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStock4EvrDay(String code){
        return stockService.getStock4EvrDay(code);
    }

}
